package com.hrs.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hrs.pojo.User;
import com.hrs.service.UserService;

@Controller
public class UserController {

	@Resource
	private UserService userService;
	
	@RequestMapping("/index")
	public String index() {
		return "index";
	}
	
	
	@RequestMapping("/login")
	public String loginShow(User user) {
		return "login";
	}
	
	@RequestMapping("/loginDo")
	public String loginDo(User user,HttpServletRequest request,Model model) {
		
		User loginUser=userService.login(user);
		if (loginUser!=null) {
			HttpSession session = request.getSession();
			session.setAttribute("USER_SESSION", loginUser);
			return "redirect:/index.do";
		}else {
			model.addAttribute("errMsg","账号或密码错误");
			return "login";
		}
	}
	
	
	
	
	
	@RequestMapping("/zc")
	public String zc() {
		return "zc";
	}
	
}
